package com.dartfar.mail.service;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.type.IntegerType;
import org.hibernate.type.Type;
import org.springframework.stereotype.Component;

import com.dartfar.base.dao.DaoUtil;
import com.dartfar.mail.model.SendState;

@Component("sendStateService")
public class SendStateServiceImpl implements SendStateService {

	private DaoUtil<SendState> sendStateDaoUtil;
	
	@Override
	public Boolean checkEmail(int id) {
		// TODO Auto-generated method stub
		List<SendState> list = sendStateDaoUtil.getList("from SendState s where s.mail.id = ?", new Object[]{id},new Type[]{new IntegerType()});
		if (list.isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public List<SendState> getSendListById(int userid) {
		// TODO Auto-generated method stub
		List<SendState> list = sendStateDaoUtil.getList("from SendState s where s.sendUser.id = ? order by s.sendDate desc", new Object[]{userid},new Type[]{new IntegerType()});
		if (list.isEmpty()) {
			return null;
		} else {
			return list;
		}
	}
	
	
	@Resource
	public void setSendStateDaoUtil(DaoUtil<SendState> sendStateDaoUtil) {
		this.sendStateDaoUtil = sendStateDaoUtil;
	}
	
	

}
